﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using eCRAM.Model;
using eCRAM.Tools;
using System.Globalization;

namespace eCRAM.WebSite.Models
{
    /// <summary>
    /// Modèle de données pour l'affichage d'un cram
    /// </summary>
    public class CramModels
    {
        /// <summary>
        /// Identifiant
        /// </summary>
        public Guid Id { get; set; }
        /// <summary>
        /// Identifiant de l'utilisateur
        /// </summary>
        public Guid UserId { get; set; }
        /// <summary>
        /// Mois concerné par le Cram
        /// </summary>
        public int Month { get; set; }
        /// <summary>
        /// Année du Cram
        /// </summary>
        public int Year { get; set; }
        /// <summary>
        /// Commentaire sur le Cram
        /// </summary>
        public string Comment { get; set; }
        /// <summary>
        /// Nom 
        /// </summary>
        public string UserName { get; set; }

        /// <summary>
        /// Role 
        /// </summary>
        public int UserRole { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public int Status { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string StatusLabel { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public List<CramLineModels> CramlinesModel { get; set; }

        public List<CramAttachmentModels> CramAttachments { get; set; }

        

        /// <summary>
        /// 
        /// </summary>
        public HttpPostedFileBase Attachment { get; set; }

        public string AttachmentName { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public decimal WorkedDays
        {
            get
            {
                return CramlinesModel.Where(x =>!x.Activity.IsAstreinte && !x.Activity.ActivityType.IsHoliday).Sum(x => x.Total);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public decimal VacationDays
        {
            get { return CramlinesModel.Where(x => !x.Activity.IsAstreinte && x.Activity.ActivityType.IsHoliday).Sum(x => x.Total); }
        }

        /// <summary>
        /// 
        /// </summary>
        public int WorkingDays
        {
            get
            {
                return WorkingDay.MonthWorkingDays(Year, Month).Count(x => x);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="idMonth"></param>
        /// <returns></returns>
        public string GetMonthName(int idMonth)
        {
            var formatInfoinfo = new DateTimeFormatInfo();
            string[] monthName = formatInfoinfo.MonthNames;
            return monthName[idMonth - 1];
        }
    }


    public class CramAttachmentModels
    {
        /// <summary>
        /// Identifiant
        /// </summary>
        public Guid Id { get; set; }

        /// <summary>
        /// Identifiant du cram
        /// </summary>
        public Guid CramId { get; set; }

        /// <summary>
        /// Nom de la pièce jointe
        /// </summary>
        public string AttachmentName { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public CramAttachmentDataModels AttachmentDatas { get; set; }

    }

    public class CramAttachmentDataModels
    {
        /// <summary>
        /// Identifiant
        /// </summary>
        public Guid AttachmentId { get; set; }

        /// <summary>
        /// données de la pièce jointe
        /// </summary>
        public byte[] Datas { get; set; }

    }


    /// <summary>
    /// 
    /// </summary>
    public class CramLineModels
    {
        /// <summary>
        /// 
        /// </summary>
        public Guid Id { get; set; }
        /// <summary>
        /// /
        /// </summary>
        public Activity Activity { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Dictionary<int, decimal> Rates { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal Total { get { return Rates.Values.Sum(); } }

        public int Status { get; set; }

        public bool Selected { get; set; }
    }

    /// <summary>
    /// 
    /// </summary>
    public class CramDailyActivityModels
    {
        /// <summary>
        /// 
        /// </summary>
        public Guid Id { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Guid CramLineId { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public DateTime Day { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal Value { get; set; }
    }

    /// <summary>
    /// 
    /// </summary>
    public class ActivityModels
    {
        /// <summary>
        /// 
        /// </summary>
        public List<Activity> Activities { get; set; }

    }
}